home *** CD-ROM | disk | FTP | other *** search
- ' Caption: Module Header...|
- ' Hint: Add Module Header|
- ' Icon: mhead.ico|
- '
- ' syn
- ' Copyright (C) 2000-2003, Ascher Stefan. All rights reserved.
- ' stievie@utanet.at, http://web.utanet.at/ascherst/
- '
- ' The contents of this file are subject to the Mozilla Public License
- ' Version 1.1 (the "License"); you may not use this file except in compliance
- ' with the License. You may obtain a copy of the License at
- ' http://www.mozilla.org/MPL/
- '
- ' Software distributed under the License is distributed on an "AS IS" basis,
- ' WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
- ' the specific language governing rights and limitations under the License.
- '
- ' The Original Code is mhead.vbs, released Sun, 26 May 2002 10:55:39 UTC.
- '
- ' The Initial Developer of the Original Code is Ascher Stefan.
- ' Portions created by Ascher Stefan are Copyright (C) 2000-2003 Ascher Stefan.
- ' All Rights Reserved.
- '
- ' Contributor(s): .
- '
- ' Alternatively, the contents of this file may be used under the terms of the
- ' GNU General Public License Version 2 or later (the "GPL"), in which case
- ' the provisions of the GPL are applicable instead of those above.
- ' If you wish to allow use of your version of this file only under the terms
- ' of the GPL and not to allow others to use your version of this file
- ' under the MPL, indicate your decision by deleting the provisions above and
- ' replace them with the notice and other provisions required by the GPL.
- ' If you do not delete the provisions above, a recipient may use your version
- ' of this file under either the MPL or the GPL.
- '
- ' You may retrieve the latest version of this file at the syn home page,
- ' located at http://syn.sourceforge.net/
- '
- ' $Id: mhead.vbs,v 1.5.2.5 2003/08/13 00:38:45 neum Exp $
-
- option explicit
-
- '#include <cmnfunc>
- '#include <consts>
-
- const RegKey = "HKCU\Software\Ascher\syn\Macros"
- dim MHForm
- dim EditName, EditPurpose, EditAuthor, EditCopy, EditDate, EditState
- dim chkTop
-
- sub Main(FileName)
- dim Label1, Label2, Label3, Label4, Label5, Label6, Label7
- dim MemoDesc
- dim BtnOK, BtnCancel
- dim icofile
-
- if Documents.Count = 0 then
- MsgBox "No Document open.", vbCritical
- exit sub
- end if
-
- MHForm = Create("TForm", Self)
- with MHForm
- .Caption = "Add Header"
- .Position = "poOwnerFormCenter"
- .BorderStyle = "bsSizeable"
- .BorderIcons = "biSystemMenu"
- icofile = ChangeFileExt(FileName, ".ico")
- if FileExists(icofile) then
- .Icon.LoadFromFile(icofile)
- end if
- .Width = 370
- .Height = 250
- .Constraints.MinHeight = Height
- .Constraints.MinWidth = Width
- end with
- EditName = Create("TEdit", MHForm)
- with EditName
- .Parent = MHForm
- .Anchors = "akLeft,akTop,akRight"
- .Left = 80
- .Top = 8
- .Width = 200
- .Text = ChangeFileExt(ActiveDocument.FileTitle, "")
- end with
- Label1 = Create("TLabel", MHForm)
- with Label1
- .Parent = MHForm
- .Caption = "&Name:"
- .Left = 8
- .Top = 12
- .FocusControl = EditName
- end with
- EditPurpose = Create("TEdit", MHForm)
- with EditPurpose
- .Parent = MHForm
- .Anchors = "akLeft,akTop,akRight"
- .Left = 80
- .Top = 33
- .Width = 200
- end with
- Label2 = Create("TLabel", MHForm)
- with Label2
- .Parent = MHForm
- .Caption = "&Purpose:"
- .Left = 8
- .Top = 37
- .FocusControl = EditPurpose
- end with
- EditAuthor = Create("TEdit", MHForm)
- with EditAuthor
- .Parent = MHForm
- .Anchors = "akLeft,akTop,akRight"
- .Left = 80
- .Top = 58
- .Width = 200
- .Text = RegGetSettings(AddBackslash(RegKey) & "ah_author", "")
- end with
- Label3 = Create("TLabel", MHForm)
- with Label3
- .Parent = MHForm
- .Caption = "&Author:"
- .Left = 8
- .Top = 62
- .FocusControl = EditAuthor
- end with
- EditCopy = Create("TEdit", MHForm)
- with EditCopy
- .Parent = MHForm
- .Anchors = "akLeft,akTop,akRight"
- .Left = 80
- .Top = 83
- .Width = 200
- .Text = RegGetSettings(AddBackslash(RegKey) & "ah_copy", "")
- end with
- Label4 = Create("TLabel", MHForm)
- with Label4
- .Parent = MHForm
- .Caption = "&Copyright:"
- .Left = 8
- .Top = 87
- .FocusControl = EditCopy
- end with
- EditDate = Create("TEdit", MHForm)
- with EditDate
- .Parent = MHForm
- .Anchors = "akLeft,akTop,akRight"
- .Left = 80
- .Top = 108
- .Width = 200
- .Text = Now
- end with
- Label5 = Create("TLabel", MHForm)
- with Label5
- .Parent = MHForm
- .Caption = "&Date/Time:"
- .Left = 8
- .Top = 112
- .FocusControl = EditDate
- end with
- MemoDesc = Create("TMemo", MHForm)
- with MemoDesc
- .Parent = MHForm
- .Anchors = "akLeft,akTop,akRight,akBottom"
- .Left = 80
- .Top = 133
- .Width = 285
- .Height = 110
- .ScrollBars = "ssBoth"
- end with
- Label6 = Create("TLabel", MHForm)
- with Label6
- .Parent = MHForm
- .Caption = "D&escription:"
- .Left = 8
- .Top = 133
- .FocusControl = MemoDesc
- end with
-
- BtnOK = Create("TButton", MHForm)
- with BtnOK
- .Parent = MHForm
- .Anchors = "akTop,akRight"
- .Caption = "&Insert"
- .Default = true
- .ModalResult = mrOK
- .Left = 290
- .Top = 7
- .Width = 75
- .Hint = "Insert Header"
- end with
- BtnCancel = Create("TButton", MHForm)
- with BtnCancel
- .Parent = MHForm
- .Caption = "Cancel"
- .Cancel = true
- .ModalResult = mrCancel
- .Left = 290
- .Top = 40
- .Width = 75
- .Anchors = "akTop,akRight"
- .Hint = "Close this Dialog"
- end with
- chkTop = Create("TCheckBox", MHForm)
- with chkTop
- .Parent = MHForm
- .Anchors = "akTop,akRight"
- .Caption = "&Top of file"
- .Hint = "At the Top of the file, or at the current Caret Pos"
- .Top = 85
- .Left = 290
- .Width = 80
- .Checked = RegGetSettings(AddBackslash(RegKey) & "ah_top", true)
- end with
- with MHForm
- .Width = RegGetSettings(AddBackslash(RegKey) & "ah_width", .Width)
- .Height = RegGetSettings(AddBackslash(RegKey) & "ah_height", .Height)
- end with
- if MHForm.ShowModal = mrOK then
- dim i, o
- if chkTop.Checked then
- o = 0
- else
- o = ActiveDocument.CaretY - 1
- end if
- with ActiveDocument.Lines
- .Insert o, String(75, "*")
- .Insert o + 1, "*" & Space(73) & "*"
- .Insert o + 2, "* Name : " & EditName.Text & Space(GetSpaceCount(EditName.Text)) & "*"
- .Insert o + 3, "* Purpose : " & EditPurpose.Text & Space(GetSpaceCount(EditPurpose.Text)) & "*"
- .Insert o + 4, "* Author : " & EditAuthor.Text & Space(GetSpaceCount(EditAuthor.Text)) & "*"
- .Insert o + 5, "* Copyright : " & EditCopy.Text & Space(GetSpaceCount(EditCopy.Text)) & "*"
- .Insert o + 6, "* Date : " & EditDate.Text & Space(GetSpaceCount(EditDate.Text)) & "*"
- .Insert o + 7, "* Description: " & MemoDesc.Lines(0) & Space(GetSpaceCount(MemoDesc.Lines(0))) & "*"
- for i = 1 to MemoDesc.Lines.Count - 1
- .Insert o + i + 7, "* " & MemoDesc.Lines(i) & Space(GetSpaceCount(MemoDesc.Lines(i))) & "*"
- next
- .Insert o + 7 + i, "*" & Space(73) & "*"
- .Insert o + 8 + i, String(75, "*")
- end with
- ActiveDocument.SelectRange 1, o + 1, 1, o + i + 10
- ActiveDocument.ExecCommand scEComment
- ActiveDocument.SelectRange 1, o + 1, 1, o + 1
- end if
-
- RegSetSettings AddBackslash(RegKey) & "ah_author", EditAuthor.Text
- RegSetSettings AddBackslash(RegKey) & "ah_copy", EditCopy.Text
- RegSetSettings AddBackslash(RegKey) & "ah_top", chkTop.Checked
- RegSetSettings AddBackslash(RegKey) & "ah_width", MHForm.Width
- RegSetSettings AddBackslash(RegKey) & "ah_height", MHForm.Height
- MHForm.Free
- end sub
-
- function GetSpaceCount(s)
- if Len(s) < 59 then
- GetSpaceCount = 59 - Len(s)
- else
- GetSpaceCount = Len(s)
- end if
- end function
-